package com.time.auth.common.enums;

import lombok.Getter;

/**
 * 角色类型枚举
 *
 * @author: HuangQi
 * @date: Created in 9:28 2025/9/30
 * @description: 角色类型枚举类
 */
@Getter
public enum AuthRoleTypeEnum {

    ADMIN(1, "admin"),
    MANAGER(2, "manager"),
    EDITOR(3, "editor"),
    GUEST(4, "guest");

    private final int code;
    private final String name;

    AuthRoleTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String fromCode(int code) {
        for (AuthRoleTypeEnum role : values()) {
            if (role.code == code) {
                return role.name;
            }
        }
        throw new IllegalArgumentException("未知的角色代码: " + code);
    }

    public static AuthRoleTypeEnum getByCode(int codeVal) {
        for (AuthRoleTypeEnum authRoleTypeEnum : AuthRoleTypeEnum.values()) {
            if (authRoleTypeEnum.code == codeVal) {
                return authRoleTypeEnum;
            }
        }
        return null;
    }
}
